<?php
/**
 * Created by PhpStorm.
 * User: 97606
 * Date: 2019/2/22
 * Time: 16:34
 */

namespace App\Http\Controllers\NewAdmin;

use App\Http\Controllers\AdapterWebController;
use App\Modules\SubmitForm\SubmitForm as ApiComplain;
use \App\Modules\UCenter\Complain as mComplain;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class Complain extends AdapterWebController
{

    // 投诉列表
    public function index()
    {
        $postData = request()->all();
        $complains = $this->appLayerExec(mComplain::class, "getComplainList",$postData);
        return view('newAdmin.complain.index', ['complains' => $complains['res']]);
    }

    // 大图
    public function bigImage($id,$table)
    {
        $res = DB::select("select * from lv_".$table." where id = ".$id);
        return view('newAdmin.complain.big_image', ['res' => $res[0]]);
    }

    // 回复投诉
    public function editComplain(Request $request,$id)
    {
        if ($request->isMethod('get')) {
            $res = \App\Models\UCenter\Complain::where('id','=',$id)->get();
            if (!$res->isEmpty()) {
                return view('newAdmin.complain.edit_complain', ['info' => $res[0]]);
            }
            return false;
        }
        $postData = $request->all();
        $postData['id'] = $id;
        $res = $this->appLayerExec(mComplain::class, 'editComplain', $postData);
        if ($res['code'] == 200) {
            return ['status' => 0, 'msg' => '处理成功!'];
        }
        return ['status' => -1, 'msg' => '处理异常，请重试!'];
    }
}
